package com.kunyi.web.service.identity.db.mapper;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kunyi.platform.mybatis.KyBaseMapper;
import com.kunyi.web.service.identity.db.entity.domain.LeafAlloc;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName IAgentMapper
 * @Description IAgentMapper
 * @Author pengjunjun
 * @Date 2024/6/20 10:35
 * @Version 1.0
 **/
@Repository
public interface LeafAllocMapper extends KyBaseMapper<LeafAlloc> {
    /**
     * @author: zhenguo.zhuang
     * @Description 获取所有的数据
     * @Date 16:35 2024/7/5
     * @Param :
     * @return List<leafAlloc>
     **/
    default List<LeafAlloc> getAllLeafAllocs(){
        return selectList(Wrappers.lambdaQuery(LeafAlloc.class));
    }
    /**
     * @author: zhenguo.zhuang
     * @Description 获取所有的业务key
     * @Date 17:00 2024/7/5
     * @Param :
     * @return List<String>
     **/
    default List<String> getAllTags(){
        List<LeafAlloc> leafAllocs = selectList(Wrappers.lambdaQuery(LeafAlloc.class));
        return leafAllocs.stream().map(LeafAlloc::getBizTag).collect(Collectors.toList());
    }
    /**
     * @author: zhenguo.zhuang
     * @Description UPDATE leaf_alloc SET max_id = max_id + step WHERE biz_tag = #{tag}   更新maxid
     * @Date 17:05 2024/7/5
     * @Param key:
     * @return LeafAlloc
     **/
     boolean updateMaxId(@Param("tag") String key);



     /**
      * @author: zhenguo.zhuang
      * @Description
      * @Date 17:09 2024/7/5
      * @Param temp:
      * @return LeafAlloc
      **/
      default LeafAlloc getLeafAlloc(@Param("tag") String key){
          return selectOne(Wrappers.lambdaQuery(LeafAlloc.class).eq(LeafAlloc::getBizTag,key));
      }



    void updateMaxIdByCustomStep(LeafAlloc leafAlloc);
}
